package com.wh.controller.initial;

import com.wh.pojo.Product;
import com.wh.pojo.Storehouse;
import com.wh.service.initial.ProductService;
import com.wh.vo.PageResult;
import com.wh.vo.SysResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/product/")
public class ProductController {
    @Autowired
    private ProductService productService;

    @GetMapping("list")
    public SysResult getProductList(PageResult pageResult){
        pageResult = productService.getProductList(pageResult);
        return SysResult.success(pageResult);
    }

    @PostMapping("addProduct")
    public SysResult addProduct(@RequestBody Product product){
        productService.addProduct(product);
        return SysResult.success();
    }

    @PutMapping("updataProduct")
    public SysResult updataProduct(@RequestBody Product product){
        productService.updataProduct(product);
        return SysResult.success();
    }

    @DeleteMapping("delete/{barCode}")
    public SysResult deleteProduct(@PathVariable String barCode){
        productService.deleteProduct(barCode);
        return SysResult.success();
    }

    @GetMapping("getStorehouse")
    public SysResult getStorehouse(){
        List<Storehouse> storehouses = productService.getStorehouse();
        return SysResult.success(storehouses);
    }

}
